Page({
  data: {
    // 当前的位置
    latitude: "",
    longitude: "",
    markers: [],
    tabselectIndex: 0,
    fromimgisShow: false,
    actionType: 0,
    // 当前项的list——tree
    currentlistTrue: [],
    currentClicktitle: "",
    viewobj: [],
    title: "",
  },

  // 页面解析完成后执行
  onReady: function () {
    // 步骤一、常见地图实例对象
    this.mapCtx = wx.createMapContext("hotMap");
  },
  onLoad: function (e) {
    wx.setNavigationBarTitle({
      title: e.region,
    });
    this.setData({
      latitude: e.latitude,
      longitude: e.longitude,
      title: e.region,
    });
    const params = {
      area: e.region,
    };
    console.log(params);
    getApp()
      .globalData.request("/map/getViewMenu", params, "POST")
      .then((res) => {
        console.log(res, "查询树状图返回信息");
        if (res.code == 200) {
          this.setData({
            currentlistTrue: res.data,
          });
        }
      });
  },

  /**
   * methods
   */
  // 初始化数据
  initInfos() {
    // 中心点自定义样式
    const markers = [];
    markers.push({
      id: 9999,
      latitude: this.data.latitude,
      longitude: this.data.longitude,
      name: "",
      iconPath:
        " https://zx-1311146360.cos.ap-shanghai.myqcloud.com/version01/center-location2.png",
      desc: "",
      title: "",
      width: 23,
      height: 31,
    });
    this.setData({
      markers: markers,
    });
  },
  tabselectChange(e) {
    this.setData({
      tabselectIndex: e.detail.index,
    });
  },
  // 点击查看报表
  itemClick(e) {
    console.log(e.currentTarget.dataset.viewname);
    this.setData({
      fromimgisShow: true,
      currentClicktitle: e.currentTarget.dataset.viewname,
    });
    const params = {
      name: e.currentTarget.dataset.viewname,
      area: this.data.title,
    };
    console.log(params);
    getApp()
      .globalData.request("/map/getViewInfo", params, "POST")
      .then((res) => {
        console.log(res, "res");
        if (res.code == 200) {
          // 去重复
          const singleList = this.removeDuplicateObj(res.data);
          console.log(singleList, "singleList");
          this.setData({
            viewobj: singleList,
          });
          console.log(res.data, "res.data");
        }
      });
  },
  // 查找重复的数据,并且重新排列
  removeDuplicateObj(arr) {
    const newArr = arr.filter(
      (pre) => pre.remark && pre.area === this.data.title
    );
    newArr.forEach((element) => {
      element.repeat = element.name + element.parentName + element.path;
    });
    let obj1 = {};
    let arr1 = [];
    // console.log(arr, "arr");
    arr1 = newArr.reduce((newArr, next) => {
      obj1[next.repeat] ? "" : (obj1[next.repeat] = 1 && newArr.push(next));
      return newArr;
    }, []);
    console.log(arr1, "arr1");
    return arr1;
  },
  formimgback() {
    this.setData({
      fromimgisShow: false,
    });
  },
  // 扩展
  open() {
    this.setData({
      actionType: 1,
    });
  },

  // 收缩
  close() {
    this.setData({
      actionType: 0,
    });
  },
});
